using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TurbaconPhone
{
    public class GameplayHUD
    {
        SpriteFont Font, BigFont;
        Vector2 Bounds;
        Wall left, right;
        float Fadeout = 2f;
        float fade = 0;
        bool fading = false;
        CharacterTeam team;
        Vector2 rtSize, btSize;

        public GameplayHUD(Vector2 bounds, Wall l, Wall r)
        {
            Bounds = bounds;
            Font = TurBacon.Content.GetFont("font");
            BigFont = TurBacon.Content.GetFont("bigFont");
            left = l;
            right = r;
            rtSize = BigFont.MeasureString("RED TEAM GOAL!");
            btSize = BigFont.MeasureString("BLUE TEAM GOAL!");
        }

        public void Update(GameTime gameTime)
        {
            if (fading)
            {
                fade += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (fade >= Fadeout)
                {
                    fade -= Fadeout;
                    fading = false;
                }
            }
        }
        
        public void goal(CharacterTeam team)
        {
            this.team = team;
            fading = true;
            fade = 0;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.DrawString(Font, "Red Health: " + left.Health, Vector2.Zero, Color.LimeGreen);
            spriteBatch.DrawString(Font, "Red Score: " + TurBacon.GameInfo.redScore, new Vector2(0, 20), Color.LimeGreen);
            spriteBatch.DrawString(Font, "Blue Health: " + right.Health, new Vector2(Bounds.X - Font.MeasureString("Blue Health: " + right.Health).X, 0), Color.LimeGreen);
            spriteBatch.DrawString(Font, "Blue Score: " + TurBacon.GameInfo.blueScore, new Vector2(Bounds.X - Font.MeasureString("Blue Score: " + right.Health).X, 20), Color.LimeGreen);

            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
            if (fading && !TurBacon.GameInfo.gameOver)
            {
                spriteBatch.DrawString(BigFont, ((team == CharacterTeam.Red) ? "RED TEAM" : "BLUE TEAM" )+ " GOAL!", new Vector2(Bounds.X / 2, Bounds.Y / 2) - ((team == CharacterTeam.Red) ? rtSize/2 : btSize/2),
                    new Color(new Vector4(1, 1, 1, Fadeout - fade)));
            }
            spriteBatch.End();
        }    
    }
}
